package chaoyue.study.thread;

import chaoyue.study.ThreadUtils;

/**
 * join方法可以让调用的线程对象插入到当前线程之前来执行
 */
public class ThreadJoin {
    public static void main(String[] args) throws Exception{
        System.out.println("main start..." + Thread.currentThread().getName());
        Thread t1 = new Thread(() -> {
            System.out.println("thread start..." + Thread.currentThread().getName());
            ThreadUtils.sleep();
            System.out.println("thread end..." + Thread.currentThread().getName());
        });
        t1.start();
        t1.join(); // 使用join方法，让t1线程先执行完再执行main线程
        System.out.println("main end..." + Thread.currentThread().getName());
    }
}
